package com.breeze.breezelive;

import android.graphics.SurfaceTexture;
import android.os.Bundle;
import android.view.Surface;
import android.view.TextureView;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import com.breeze.breezelive.play.LivePlayer;

import java.io.File;

public class PlayActivity extends AppCompatActivity implements TextureView.SurfaceTextureListener {
    private static final String TAG = "PlayActivity";
    private TextureView mTextureView;
    private String path;
    private int videoWidth, videoHeight;
    private LivePlayer livePlayer;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_play);
        init();
    }

    private void init() {
        path = new File(getExternalFilesDir("temp"), "abc.mp4").getAbsolutePath();
        videoWidth = 1920;
        videoHeight = 1080;
        mTextureView = findViewById(R.id.video_view);
        mTextureView.setSurfaceTextureListener(this);

        livePlayer = new LivePlayer(path);
        livePlayer.setVideoSize(videoWidth, videoHeight);
    }

    @Override
    public void onSurfaceTextureAvailable(@NonNull SurfaceTexture surface, int width, int height) {
        livePlayer.setSurface(new Surface(surface));
        livePlayer.start();
    }

    @Override
    public void onSurfaceTextureSizeChanged(@NonNull SurfaceTexture surface, int width, int height) {

    }

    @Override
    public boolean onSurfaceTextureDestroyed(@NonNull SurfaceTexture surface) {
        return false;
    }

    @Override
    public void onSurfaceTextureUpdated(@NonNull SurfaceTexture surface) {

    }
}